//*****************************************************************************
//
// Copyright, (C) 2000-2005 Quantic Dream SA
//
// These coded instructions, statements and computer programs contain
// unpublished information, proprietary to Quantic Dream SA and are 
// protected by French and EEC copyright laws. They may not be 
// disclosed to third parties or copied or duplicated, in whole or in part, 
// without prior written consent of Quantic Dream SA
//
// Unpublished-rights reserved under the Copyright Laws of the EEC.
//
//*****************************************************************************
//
//	CLASS:	QtRenderWidget
//	The QtRenderWidget class implements ...
//
//	JJA : 2012-07-23 - Created
//*****************************************************************************

//=============================================================================
//	CODE STARTS HERE
//=============================================================================

#ifndef QT_RENDER_WIDGET_H
#define QT_RENDER_WIDGET_H

#include <QGLWidget>
#include <QTimer>
#include <QElapsedTimer>

#include <Math/MathDefines.h>

class MESH;
class MESH_INSTANCE;
class SHADER;
class CAMERA;

class QtRenderWidget: public QGLWidget
{
							Q_OBJECT

public:
							ALIGNED_NEW_DELETE( 16 )

							QtRenderWidget( const QGLFormat& OpenGLFormat, QWidget* pParent );

	static void				CreateTriangleMeshData();
	static void				CreatePlaneMeshData();

protected:
	virtual void			initializeGL();
	virtual void			resizeGL(int w, int h);
	virtual void			paintGL();

	virtual void			keyPressEvent( QKeyEvent* event );
	virtual void			keyReleaseEvent( QKeyEvent* event );

	virtual void			mousePressEvent( QMouseEvent* event );
	virtual void			mouseReleaseEvent( QMouseEvent* event );
	virtual void			mouseMoveEvent( QMouseEvent* event );

public slots:
	void					MainLoop();
	void					FpsTimerLoop();

private:
	enum SHADER_ID
	{
		SHADER_ID_COLOR_PER_VERTEX,
		SHADER_ID_GOURAUD,
		SHADER_ID_COUNT
	};

	QVector<MESH*>			_lpMeshes;
	QVector<MESH_INSTANCE*>	_lpMeshInstances;
	SHADER*					_pShaderArray[SHADER_ID_COUNT];
	CAMERA*					_pCamera;

	QTimer					_MainLoopTimer;
	QTimer					_FpsTimer;
	QElapsedTimer			_FrameTimer;

	VECTOR3					_vCameraTranslationVector;

	QPoint					_LastMousePosition;
	int						_nCameraDeltaHead;
	int						_nCameraDeltaPitch;

	unsigned int			_uiFramesCount;
	unsigned int			_uiFpsTimer;

	static QByteArray		_TriangleMeshData;
	static QByteArray		_PlaneMeshData;

	static float			_fCameraTranslationSpeed;
	static float			_fCameraRotationSpeed;
};

#endif

//=============================================================================
//	CODE ENDS HERE
//=============================================================================